let orgainPage = Page; // 保存原本的Page对象
import rootList from './rootList';
import nav from './nav';
let basePage = function (data) {
    if (typeof data.data.dataVal === 'undefined') {}
    let orgainOnLoad = data.onLoad;
    data.onLoad = function (o) {
        orgainOnLoad.call(this, o);
    }
    // 获取用户登录信息
    data.getUserLoginInfo = async () => {
        let token = wx.getStorageSync('flower2025-token');
        let user = wx.getStorageSync('currentUser');
        let NewCurrentPages = getCurrentPages();
        if (NewCurrentPages.length != 0) {
            let res = await rootList.PageWhiteList.includes('/' + NewCurrentPages[NewCurrentPages.length - 1].route);
            // 不在白名单内，走用户校验信息
            if (!res) {
                if (user && user.userMobile == null) {
                    wx.showToast({
                        title: '请授权登录后继续.',
                        success() {
                            wx.navigateTo({
                                url: '/pages/login/login',
                            })
                        }
                    })
                } else {
                    // 重新获取信息
                    setTimeout(() => {
                        data.getUserLoginInfo();
                    }, 200)
                }
            }
        }

    }
    let orgainOnShow = data.onShow;
    data.onShow = async function (o) {
        data.getUserLoginInfo();
        orgainOnShow.call(this, o);
    }
    let orgainOnHide = data.onHide;
    data.onHide = function (o) {
        orgainOnHide.call(this, o);
    }
    let orgainOnUnload = data.onUnload;
    data.onUnload = function (o) {
        orgainOnUnload.call(this, o);
    }
    // 新增权限跳转函数
    data.navTo = nav.navTo;
    return orgainPage(data);
};
module.exports = {
    basePage
}